// todo============= 顶部Tab栏=========================
async function top_render() {
    const res = await axios.get('/index/index')
    // console.log(res);
    const newData = res.data.data.allCate
    // console.log(newData);
    document.querySelector('.container ul').innerHTML = newData.map((item) => {
        return `  
        <li class="menu-item menu-item-type-taxonomy menu-item-object-category ">
            <a title="" href="index.html"><span class="fa ${item.icon}"></span>${item.catename}</a>
        </li>
        `
    }).join('')
}
top_render()



// todo ====================== 左边文章  ============================
function getList1() {
    axios.get('http://124.223.14.236:8060/index/list?page=1&limit=10&cateid=9').then((res) => {
        console.log(res)

        let newList1 = res.data.data.list.data.map((item) => {
            return `
            <article class="excerpt excerpt-one">
            <header>
              <h2>
                <a target="_blank" href="show.html" title="阿里云拼团推荐服务器">${item.title}</a>
              </h2>
            </header>
            <p class="text-muted time">
              <a href="">${item.author}</a> 发布于 2018-03-30
            </p>
            <p class="focus">
              <a target="_blank" href="http://blog.weknow.cn/474.shtml" class="thumbnail">
                <span class="item"><span class="thumb-span"><img src="http://124.223.14.236:8060/${item.pic}"
                      class="thumb" /></span></span></a>
            </p>
            <p class="note"></p>
            <p class="text-muted views">
              <span class="post-views">阅读(${item.click})</span>
              <span class="post-comments">评论(${item.istop})</span>
              <a href="javascript:;" class="post-like">
                <i class="fa fa-thumbs-up"></i>赞 (<span>${item.ishot}</span>)
              </a>
              <span class="post-tags">标签：${item.tags}
                
            </p>
          </article> 
            `
        })
        $('.excerpt.excerpt-one').html(newList1.join(''))
    })
}
getList1()


// todo =============== 侧边图片 渲染 =====================
async function right_Render() {
    const res = await axios.get('/index/index')
    // console.log(res.data.data);
    const newDatatwo = res.data.data.sideBanner
    document.querySelector('.textwidget').innerHTML = newDatatwo.map((item) => {
        return ` 
         <a href="${item.advimglink}" rel="nofollow" target="_blank" title="${item.advimgdesc}">
            <img class="g430" style="width:360px;height:133px;" src="http://124.223.14.236:8060/${item.advimgsrc}" alt="阿里云开学季">
         </a>
       `
    }).join('')
}
right_Render()


//todo ================ 热门标签开始 渲染 =======================
async function render_Hot() {
    const res = await axios.get('/index/index')
    // console.log(res);
    // console.log(res.data.data.allTag);
    const newData = res.data.data.allTag
    // console.log(newData);
    document.querySelector('.widget_tags ul').innerHTML = newData.map((item) => {
        return ` 
             <li><a title="" href="">${item.tagname}</a></li>
            `
    }).join('')
}
render_Hot()


//todo ================ 友情链接开始 渲染 =======================
async function hot_right_render() {
    const res = await axios.get('/index/index')
    // console.log(res);
    // console.log(res.data.data.allLink);
    const newData = res.data.data.allLink
    // console.log(newData);
    document.querySelector('.widget_comments ul').innerHTML = newData.map((item) => {
        return ` 
            <li>
                <a href="${item.url}"><img src="http://124.223.14.236:8060/${item.img}" alt="">
                    <p>${item.des}</p>
                </a>
            </li >
        `
    }).join('')
}
hot_right_render()

//todo ================ 热门文章开始 渲染 =======================
async function article_render() {
    const res = await axios.get('/index/new')
    // console.log(res.data.data.list.data);
    const newData = res.data.data.list.data
    // console.log(newData);
    document.querySelector('.widget ul').innerHTML = newData.map((item) => {
        return ` 
        <li>
            <a target="_blank" href="">
            <span class="thumbnail">
                <img src="http://124.223.14.236:8060/${item.pic}" class="thumb" />
            </span>
            <span class="text">${item.title}</span>
            <span class="text-muted post-views">阅读${item.click}</span>
            </a>
        </li>
        `
    }).join('')
}
article_render()

// //todo ================ 底部 友情链接  =======================
async function bottom_render() {
    const res = await axios.get('/index/index')
    // console.log(res);
    // console.log(res.data.data.allLink);
    const newData = res.data.data.allLink
    // console.log(newData);
    document.querySelector('.footer .link').innerHTML = newData.map((item) => {
        return ` 
        <a href="" title="obj.des">${item.des}</a> <span>|</span>
        `
    }).join('')
}
bottom_render()


// //todo ================ 底部 版权 ==========================
async function copyright_render() {
    const res = await axios.get('/index/index')
    // console.log(res);
    const newData = res.data.data.config.allData
    // console.log(newData);
    newData.forEach((item) => {
        if (item.id === 55) {
            document.querySelector('.footer p').innerHTML = ` <p>&copy; 2021 <a href="http://blog.weknow.cn">优点达资讯,</a>
            &nbsp;&nbsp;联系邮箱：${item.attr_value}
            &nbsp;&nbsp; <a href="">备案号信息</a>
            </p>`
            // document.querySelector('.footer p').innerHTML = newData.map((item) => {
            //     return `
            // <p>&copy; 2021 <a href="http://blog.weknow.cn">优点达资讯,</a>
            // &nbsp;&nbsp;联系邮箱：${item.attr_value}
            // &nbsp;&nbsp; <a href="">备案号信息</a>
            // </p>
            //     `
            // }).join('')
        }
    });
}
copyright_render()


// todo ===================== 顶部 登入注册功能 ==============================
async function getuser() {
    const {data:{data}} = await axios.get('user/getUserInfo', {
        headers: { token: localStorage.getItem('token')}
    })
    console.log(data);
    // 账号信息
    document.querySelector('.slinks').innerHTML = `
     <i class="iconfont icon-yonghu"></i>你好${data.userInfo.username} 
    <i class="iconfont icon-exit-full"></i>
    `
}
getuser()



